package com.huawei.appmarket.service.usercenter.userinfo.view.activity;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.FontMetrics;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailScreenBean;
import java.util.Locale;
import o.der.b;
import o.dof;
import o.epr;

public class SearchBar extends View {
    private static final String[] ˊ = new String[]{"#", "A", "BCDEFGHIJKLM", "N", "OPQRSTUVWXY", "Z"};
    private static final String[] ˋ = new String[]{"#", "A", "BCD", "E", "FGH", "I", "JK", "L", "MN", "O", "PQ", "R", "STU", "V", "WXY", "Z"};
    private static final String[] ॱ = new String[]{"#", "A", "B", "C", "D", "E", "F", "G", DetailScreenBean.IMG_TAG_HORIZENTAL, "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
    private TextView ʻ;
    private int ʼ = 20;
    private Paint ʽ;
    private int ˎ = -1;
    private String[] ˏ = ॱ;
    private String ˏॱ = "#";
    private int ͺ = 36;
    private int ॱˊ = 36;
    private int ॱॱ;
    private a ᐝ;

    public interface a {
        void ˋ(String str);
    }

    public SearchBar(Context context) {
        super(context);
        ˎ();
    }

    public SearchBar(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        ˎ();
    }

    public SearchBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˎ();
    }

    private void ˎ() {
        this.ʽ = new Paint();
        ˋ();
    }

    private void ˋ() {
        this.ʽ.reset();
        this.ʽ.setColor(getResources().getColor(o.der.a.ˎ));
        this.ʽ.setTextAlign(Align.CENTER);
        this.ʽ.setAntiAlias(true);
        this.ʽ.setStrokeWidth(3.0f);
        this.ʽ.setTextSize(getResources().getDimension(b.ᐝ));
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        Configuration configuration = getResources().getConfiguration();
        if (!epr.ˎ().ॱॱ()) {
            if (configuration.orientation == 2) {
                this.ˏ = ˋ;
            } else if (configuration.orientation == 1) {
                this.ˏ = ॱ;
            }
        }
    }

    private void ˊ() {
        Configuration configuration = getResources().getConfiguration();
        if (!epr.ˎ().ॱॱ()) {
            if (configuration.orientation == 2) {
                this.ˏ = ˋ;
            } else if (configuration.orientation == 1) {
                this.ˏ = ॱ;
            }
        }
        if (!ॱ()) {
            if (this.ˏ == ॱ) {
                this.ˏ = ˋ;
                if (!ॱ()) {
                    this.ˏ = ˊ;
                    ॱ();
                }
            } else if (this.ˏ == ˋ) {
                this.ˏ = ˊ;
                ॱ();
            }
        }
    }

    private boolean ॱ() {
        FontMetrics fontMetrics = this.ʽ.getFontMetrics();
        this.ʼ = ((int) Math.ceil((double) (fontMetrics.descent - fontMetrics.top))) / 2;
        this.ॱॱ = ((getHeight() - (this.ॱˊ + this.ͺ)) - (this.ʼ / 2)) / (this.ˏ.length - 1);
        if (((int) ((this.ˏ == ˋ ? 0.3d : 0.6d) * ((double) this.ʼ))) + this.ʼ <= this.ॱॱ) {
            return true;
        }
        return false;
    }

    public void ˎ(Canvas canvas) {
        ˊ();
        float width = ((float) getWidth()) / 2.0f;
        float f = (float) (this.ॱˊ + this.ʼ);
        for (int i = 0; i < this.ˏ.length; i++) {
            Resources resources = getResources();
            if (this.ˏ[i].contains(this.ˏॱ)) {
                this.ʽ.setColor(getContext().getResources().getColor(o.der.a.ॱॱ));
                this.ʽ.setFakeBoldText(true);
            } else {
                this.ʽ.setFakeBoldText(false);
                this.ʽ.setColor(resources.getColor(o.der.a.ˎ));
            }
            if (this.ˏ[i].length() == 1) {
                canvas.drawText(this.ˏ[i], width, f, this.ʽ);
            } else {
                String str = "•";
                canvas.drawText("•", width, f, this.ʽ);
            }
            f += (float) this.ॱॱ;
        }
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        ˎ(canvas);
    }

    public boolean dispatchTouchEvent(MotionEvent motionEvent) {
        int action = motionEvent.getAction();
        float y = motionEvent.getY();
        int i = this.ˎ;
        if (this.ॱॱ != 0) {
            int i2 = (int) (((y - ((float) this.ॱˊ)) + ((float) (((double) (((float) this.ॱॱ) - ((float) this.ʼ))) / 2.0d))) / ((float) this.ॱॱ));
            if (action == 1) {
                this.ˎ = -1;
                if (this.ʻ != null) {
                    this.ʻ.setVisibility(4);
                }
            } else if (i != i2 && i2 >= 0 && i2 < this.ˏ.length) {
                if (this.ᐝ != null) {
                    this.ᐝ.ˋ(this.ˏ[i2]);
                }
                ॱ(this.ˏ[i2]);
                if (this.ʻ != null) {
                    this.ʻ.setText(this.ˏ[i2]);
                    this.ʻ.setVisibility(0);
                }
                this.ˎ = i2;
            }
            invalidate();
        }
        return true;
    }

    public void ॱ(String str) {
        String ˊ = ˊ(str);
        if (!ˊ.isEmpty() && this.ˏॱ != null && !this.ˏॱ.equals(ˊ)) {
            this.ˏॱ = ˊ;
            invalidate();
        }
    }

    private String ˊ(String str) {
        if (dof.ˋ(str)) {
            return "";
        }
        if (str.matches("^[A-Z|a-z]$")) {
            return str.toUpperCase(Locale.getDefault());
        }
        return this.ˏ.length > 0 ? this.ˏ[0] : "";
    }

    public void setOnTouchLetterChangeListener(a aVar) {
        this.ᐝ = aVar;
    }

    public void setTvDialog(TextView textView) {
        this.ʻ = textView;
    }
}
